//
//  Person.m
//  Lesson -02
//
//  Created by dllo on 16/2/25.
//  Copyright © 2016年 Apon. All rights reserved.
//

#import "Person.h"

@implementation Person
-(void)name:(NSString *)name Sex:(NSString *)sex Age:(NSInteger)age{
    _name =name;
    _sex = sex;
    _age = age;
}
-(void)sayHi{
    
    NSLog(@"name:%@,sex:%@,age:%ld",_name,_sex,_age);

}
-(void)setName:(NSString *)name{
    _name = name;
}
-(NSString *)name{
    return _name;
 
}

//重写init方法

-(instancetype)init{
    //1 . 调用父类的init方法,self指对象本身,
   self = [super init];
    //添加一个判断条件,当self指针不为空时,再进行赋值
    if (self) {
     //给某个实例变量赋值,
        _age  = 20;
        
    }
    return self;
}


//自定义初始化
-(instancetype)initWithName:(NSString *)name{
    self = [super init];
    if (self) {
        //自定义实例变量赋值
        _name = name;
    }
    return self;
}

-(instancetype)initWithName:(NSString *)name sex:(NSString *)sex age:(NSInteger)age{

    self = [super init];
    if (self) {
        _name =name;
        _sex=sex;
        _age = age;
        
    }
    return self;
}

//构造器相关实现 代码!!!!
+(instancetype)person{
  //封装alloc init
  Person *per =[[Person alloc]init];
   //返回创建出来的对象
    return per;
}

+(instancetype)personWithName:(NSString *)name sex:(NSString *)sex age:(NSInteger)age{
 
    return [[Person alloc]initWithName:name sex:sex age:age];


}













@end
